package cn.cas.mango.util;

import cn.cas.mango.dto.param.AggParam;
import cn.cas.mango.dto.param.GlobalParam;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

public class CheckParam {
  private static String getToday() {
    LocalDate localDate = LocalDate.now();
      return localDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
  }
  public static void checkGlobal(GlobalParam globalParam) {
    if(globalParam.getClusterSize() == null) {
      globalParam.setClusterSize(100000);
    }

    if (globalParam.getToGraph() == null) {
      globalParam.setToGraph(false);
    }
    if (globalParam.getPageSize() == null || globalParam.getPageSize() <= 0) {
      globalParam.setPageSize(20000);
    }
    if (globalParam.getMaxClusterSize() == null) {
      globalParam.setMaxClusterSize(3000);
    }
    if (globalParam.getSimParam() == null) {
      globalParam.setSimParam(-1.0);
    }
    if (globalParam.getAddScore() == null) {
      globalParam.setAddScore(false);
    }
    if (globalParam.getV() == null) {
      globalParam.setV("");
    }
    String today = getToday();
    if (globalParam.getStartDate() == null || globalParam.getStartDate().compareTo(today) > 0) {
      globalParam.setStartDate("1900-01-01");
    }
    if (globalParam.getEndDate() == null) {
      globalParam.setEndDate(today);
    }
  }

  public static void checkAgg(AggParam aggParam) {
    if (aggParam.getGetModel() == null) {
      aggParam.setGetModel(true);
    }
    if (aggParam.getGetField() == null) {
      aggParam.setGetField("cluster_id3");
    }
    if (aggParam.getShowAll() == null) {
      aggParam.setShowAll(true);
    }
    if (aggParam.getSize() == null) {
      aggParam.setSize(30000);
    }
    if (aggParam.getOneSize() == null) {
      aggParam.setOneSize(1000);
    }

    if (aggParam.getClusterType() == null) {
      aggParam.setClusterType("all");
    }
  }
}
